//
//  HeadView.m
//  tupianlashen
//
//  Created by lanou on 16/4/17.
//  Copyright © 2016年 lanou. All rights reserved.
//

#import "HeadView.h"

@interface HeadView ()
{
    CGRect initialFrame;
    CGFloat defaultViewHeight;
}

@end
@implementation HeadView

@synthesize tabVC = _tabVC;
@synthesize  view = _view;


- (void) stretchHeaderForTableView:(UITableView *)tabVC withView:(UIView *)view subView:(UIView *)subView;
{
    _tabVC = tabVC;
    _view = view;
    initialFrame = _view.frame;
    defaultViewHeight = initialFrame.size.height;
    UIView *emptyTableHeaderView = [[UIView alloc] initWithFrame:initialFrame];
    _tabVC.tableHeaderView = emptyTableHeaderView;
    [_tabVC addSubview:_view];
    [_tabVC addSubview:subView];
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    CGRect f = _view.frame;
    f.size.width = _tabVC.frame.size.width;
    _view.frame = f;
    
    if (scrollView.contentOffset.y < 0) {
        CGFloat offsetY = (scrollView.contentOffset.y + scrollView.contentInset.top) * -1;
        initialFrame.origin.y = - offsetY * 1;
        initialFrame.origin.x = - offsetY / 2;
        initialFrame.size.width = _tabVC.frame.size.width + offsetY;
        initialFrame.size.height = defaultViewHeight + offsetY;
        _view.frame = initialFrame;
    }
}

- (void)resizeView{
    initialFrame.size.width = _tabVC.frame.size.width;
    _view.frame = initialFrame;
}



@end
